package Server;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.jboss.netty.handler.codec.string.StringEncoder;
import org.jboss.netty.handler.execution.ExecutionHandler;

/**
 * @Author:AwakeningCode
 * @Date: Created in 23:14 2018\1\18 0018
 */
public class ServerPipeLineFactory implements ChannelPipelineFactory{

    private final ExecutionHandler executionHandler;

    public ServerPipeLineFactory(ExecutionHandler executionHandler){
        this.executionHandler = executionHandler;
    }

    public ChannelPipeline getPipeline() throws Exception {
        return Channels.pipeline(
                new StringEncoder(),
                new StringDecoder(),
                //多个pipeline之间必须共享同一个ExecutionHandler，放在业务逻辑handler之间
                executionHandler,
                new MyServerHandler()
        );
    }
}
